//InnerAudioContext实例
//const app = getApp()

 
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tips: {
      type: Array,
      value: [],
      observer: function (n) {
        if (n.length) {
          n.forEach(item => {
            if (item.type == 'warn') {
              item.w = item.tip_content.length * 40;
            } else {
              item.w = item.btn.length * 120;
            }

          })
          this.setData({
            tipsArr: n
          })
        }
      }
    },
    callbackFn: {
      type: Function,
      value: () => {}
    },
    tip0: {
      type: String,
      value: '',
      observer: function (n) {
        if (n.length) {
          this.setData({
            tip0: n
          })
        }
      }
    },
    tip1: {
      type: String,
      value: '',
      observer: function (n) {
        if (n.length) {
          this.setData({
            tip1: n
          })
        }
      }
    },
    tip2: {
      type: String,
      value: '',
      observer: function (n) {
        if (n.length) {
          this.setData({
            tip2: n
          })
        }
      }
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    pic_num:55,
    go_direction : '',
    go_num : '55',
    left_num : '65',
    right_num :'45',
    pan_rotate:0,
    pan_rotate1:0,
    clockdata:[],
  },
 /**
  * 页面加载完成执行
  */
 lifetimes:{
  ready(){
    var that =this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        // 屏幕宽度、高度
        console.log('height=' + res.windowHeight);
        console.log('width=' + res.windowWidth);
        // 高度,宽度 单位为px
        that.setData({
          windowHeight:  res.windowHeight,
          windowWidth:  res.windowWidth,
          //buttonTop1:buttonTop1,//这里定义按钮的初始位置
          //buttonLeft:res.windowWidth*0.70,//这里定义按钮的初始位置
        })
      }
    })
    

  },
  attached: function() {
    // 在组件实例进入页面节点树时执行
  },
  detached: function() {
    // 在组件实例被从页面节点树移除时执行
  },
},
 //组件所在页面的生命周期
 pageLifetimes: {
  show: function() {
    // 页面被展示
  },
  hide: function() {
    // 页面被隐藏
  },
  resize: function(size) {
    // 页面尺寸变化
  }
},
   /**
   * 组件的方法列表
   */
  methods: {
  //以下是按钮拖动事件
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
 
  //停止按钮事件
  playRight : function(e){
    var that = this;
    let pan = e.currentTarget.dataset.pan;
    var pan_rotate = that.data.pan_rotate;
    var pan_rotate1 = that.data.pan_rotate1
    console.log(pan);
    if(pan =='1' ){
      pan_rotate = that.data.pan_rotate+36;
      that.setData({
        pan_rotate:pan_rotate,
      });
    }
    else{
      pan_rotate1 = that.data.pan_rotate1+36;
      that.setData({
        pan_rotate1:pan_rotate1,
      });
    }
    console.log(that.data.pan_rotate + ' '+that.data.pan_rotate1);
    

    // setTimeout(function () {
    //   //要延时执行的代码
    //   that.doorChange(direction);
    //  }, 300) //延迟时间 这里是1秒

  },
 
  //进度条改变后触发事件
  doorChange : function(direction){
    var that = this;
    var go_num = this.data.go_num;
    //var ret = this.data.clockdata;
    var ret = wx.getStorageSync("clockdata"+go_num) || [];
    console.log('get data==='+go_num+JSON.stringify(ret))
    if(!ret){
      console.log('no data1')
      that.timeUpdate(direction);
      ret = wx.getStorageSync("clockdata"+go_num) || [];
    }
    if(ret){
      if(ret.length>0){
        console.log('no null')
      }
      else{
        console.log('no data2')
        that.timeUpdate(direction);
      }
    }
    else{
      console.log('no data3')
      //that.timeUpdate();
      ret = wx.getStorageSync("clockdata"+go_num);
    }
    ret = wx.getStorageSync("clockdata"+go_num);
    if(direction == '顺时针'){
      that.setData({
        go_num: ret[0].move_pos,
        left_num: ret[1].move_pos,
        right_num: ret[0].move_pos,
        pic_num:ret[0].move_pos,
      })
    }
    else
    {
      that.setData({
        go_num: ret[1].move_pos,
        left_num: ret[1].move_pos,
        right_num: ret[0].move_pos,
        pic_num:ret[1].move_pos,
      })
    }
    
    
    

    
    //this.playMusic();
    
  },
  /*
     * 内部私有方法建议以下划线开头
     * triggerEvent 用于触发事件
     */
    _okEvent(){
      //触发取消回调
      var that = this;
      console.log('触发取消回调')
      var isOk = 0;
      if(that.data.count>=1){
        isOk = 1;
      }
      return isOk;
      //this.triggerEvent("cancelEvent")
    },
  //进度条拖动过程中触发事件
  playReset : function(e){
    
    this.setData({
      pic_num:55,
      go_direction : '',
      go_num : '55',
      left_num : '65',
      right_num :'45',
       pan_rotate:0,
    })
    
  },
 
  //将秒钟转化为mm：ss的时间格式
  musicTimeFormat : function(time){
    var second = Math.floor(time % 60);
    if(second<10){
      second = '0' + second;
    }
    var minute = Math.floor(time / 60);
    if (minute < 10) {
      minute = '0' + minute;
    }
    return minute + ':' + second;
  },
 
  //播放的时候，更新进度条和时间显示
  timeUpdate : function(direction){
    var that = this;
    var go_num = this.data.go_num;
    wx.request({
      url: app.globalData.publicAdress + '/api/game/clockinfo',
      method: "get",
      header: {
        'content-type': 'application/json', // 默认值
        'Accept': 'application/vnd.cowsms.v2+json',
        'Authorization': 'Bearer ' + wx.getStorageSync("token"),
      },
      data: {
        name: go_num,
      },
      success: function (res) {
        wx.hideLoading()
        //console.log(JSON.stringify(res))
        //如果token失效   则返回新的token  
        if (res.header.Authorization) {
          var str = res.header.Authorization;
          // console.log(str)
          wx.removeStorageSync("token");
          wx.setStorageSync("token", str.substring(7, str.length))
        }
        if (res.statusCode == '200') {
          
          if(res.data.data != null){
            var ret = res.data.data;
            wx.setStorageSync("clockdata"+go_num,ret);
            wx.setStorage({
              key:"clockdata"+go_num,
              data:ret
            });
            console.log('ret==='+go_num+JSON.stringify(ret));
            var key = 'clockdata'+go_num;
            that.setData({
              [key]: ret, //评论列表
            })
            if(direction == '顺时针'){
              that.setData({
                go_num: ret[0].move_pos,
                left_num: ret[1].move_pos,
                right_num: ret[0].move_pos,
                pic_num:ret[0].move_pos,
              })
            }
            else
            {
              that.setData({
                go_num: ret[1].move_pos,
                left_num: ret[1].move_pos,
                right_num: ret[0].move_pos,
                pic_num:ret[1].move_pos,
              })
            }

            //console.log('new datalist==='+JSON.stringify(datalist));
          }else{
            wx.showModal({
              title: '提示',
              content: '门锁了？',
              success: (res) => {
                  // wx.switchTab({
                  //   url: '/pages/strategyList/strategyList'
                  // })                
              }
            })
          }
        }
      }
    })

    
  },
  leifent_rotate_click_left: function(per,isload) {
    var that = this
       //canOnePointMove = false;
       //console.log(e.currentTarget)
       //var top = 0,stop = 0;
      //  const query = this.createSelectorQuery()
      //  query.select('#leifengta').boundingClientRect()
      //  query.selectViewport().scrollOffset()
      //  query.exec(function (res) {
      //    //console.log(res)
      //    var top = 0,stop = 0,left=0,rotate=that.data.leifengta_rotate+3.6;
      //    //rotate = rotate*per;
      //    console.log('rotate==='+rotate);
      //    top = res[0].top // #the-id节点的上边界坐标
      //    left = res[0].left
      //    stop = res[1].scrollTop // 显示区域的竖直滚动位置
      //    that.setData({
      //      msg: '旋转1  top='+top + ' left='+left,
      //      leifengta_top:top,
      //      leifengta_left:left,
      //      leifengta_rotate:rotate,
      //    })
      //    console.log('旋转1  top='+top + ' left='+left);
      //  })
      //var rotate=that.data.leifengta_rotate+10.8;
      var rotate=that.data.leifengta_rotate+10.8;
      var rotate2 = that.data.changzhen_rotate+0.2;
      if(isload==1){
        rotate = 10.8*per;
        rotate2 = 0.2*per+45;
      }
 
      
         console.log('rotate==='+rotate);

         that.setData({
           leifengta_rotate:rotate,
           changzhen_rotate:rotate2,
         })
         //console.log('旋转1  top='+top + ' left='+left);
       //this.data.leifengta_rotate++;
       //that.rotateAni(++this.data.leifengta_rotate);
    },
      /**
 * 实现image旋转动画，每次旋转 45*n度
 */
  }
})